//
//  XMFourViewController.m
//  gpos_app
//
//  Created by apple on 2018/8/13.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XMFourViewController.h"
#import "Masonry.h"
#import "MerChentCollectionViewCell.h"
#import "MerChantInfoViewController.h"
#import "SmallTableViewCell.h"
#import "MerchentEntryViewController.h"
#import "SVProgressHUD.h"
#import "MerChantModel.h"
#import "GPosAPI.h"
#import "MJRefresh.h"
#import "XMRegisterViewController.h"
#import "MerchsCollectionViewCell.h"
#import "WKProgressHUD.h"
@interface XMFourViewController ()<UISearchBarDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UIGestureRecognizerDelegate,UITableViewDelegate,UITableViewDataSource>
{
    UICollectionView *mainCollectionView;
}
@property (nonatomic,strong) UISearchBar *searchBar;
@property (nonatomic,strong) NSMutableArray *dataArr;
@property (nonatomic,strong) UIView *smallView;
@property (nonatomic,strong) UIView *bigView;
@property (nonatomic,strong) UIImageView *imageV;
@property (nonatomic,strong) UITableView *tables;
@property (nonatomic,strong) UICollectionView *rightCollectView;
//参数
@property (nonatomic,strong) NSString *type;
@property (nonatomic,strong) NSString *name;
@property (nonatomic,assign) NSInteger pageSize;
@property (nonatomic,assign) NSInteger currentPage;
@property (nonatomic,strong) NSMutableArray *AllArr;
@property (nonatomic,strong) NSMutableArray *AllArrRight;
@property (nonatomic,strong) NSDictionary *dic;
@property (nonatomic,strong) NSMutableArray *typeArr;
@property (nonatomic,strong) NSMutableArray *typeArr1;
@property (nonatomic,strong) UIImageView *im;
@property (nonatomic,assign) NSInteger isNum;
@property (nonatomic,strong) UIView *topSmallView;
@property (nonatomic,strong) NSMutableArray *addArr;
@property (nonatomic,strong) NSMutableArray *newsAddArr;
@property (nonatomic,strong) UIView *searchView;
@property (nonatomic,strong) UISegmentedControl *segmentedControl;
@property (nonatomic,assign) NSInteger tag;
@property (nonatomic,strong)  UIView*titleView;
@property (nonatomic,assign) NSInteger pages;
@property (nonatomic,strong) WKProgressHUD *hud;
//GPOS智能商家的数组
@property (nonatomic,strong) NSMutableArray *GPOSArray;
@property (nonatomic,strong) NSMutableArray *addMoreArr;
@end

@implementation XMFourViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    self.tabBarController.tabBar.hidden=NO;
    self.navigationItem.title=@"";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shuaxin) name:@"uploadCurrentView" object:nil];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}

-(void)shuaxin{
    self.hud=[WKProgressHUD popMessage:@"提交成功" inView:self.view duration:1 animated:YES];
    self.isNum=0;
    self.dataArr=[NSMutableArray new];
    self.AllArr=[NSMutableArray new];
    self.typeArr=[NSMutableArray new];
    self.typeArr1=[NSMutableArray new];
    self.type=@"0";
    self.name=@"";
    self.pageSize=10;
    self.currentPage=1;
    //GPOS移动商家
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];
    __weak typeof(self) weakSelf = self;
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD dismiss];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                [SVProgressHUD dismiss];
                
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.status=[[data objectForKey:@"status"] integerValue];
                    group.address=[data objectForKey:@"address"];
                    group.phone=[data objectForKey:@"phone"];
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"name"];
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.picture=[data objectForKey:@"picture"];
                    group.descript=[data objectForKey:@"description"];                    [weakSelf.AllArr addObject:group];
                }
                [self->mainCollectionView reloadData];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                
                [SVProgressHUD dismiss];
                
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                
            }
            
            else{
                
                [SVProgressHUD dismiss];
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
        }
        
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor=[UIColor whiteColor];
  
   
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
    //设置成NO表示当前控件响应后会传播到其他控件上，默认为YES。
    tapGestureRecognizer.cancelsTouchesInView = NO;
    //将触摸事件添加到当前view
    [self.view addGestureRecognizer:tapGestureRecognizer];
    self.view.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1];
    self.isNum=0;
    self.dataArr=[NSMutableArray new];
    self.addArr=[NSMutableArray new];
    self.newsAddArr=[NSMutableArray new];
    self.AllArr=[NSMutableArray new];
    self.typeArr=[NSMutableArray new];
    self.typeArr1=[NSMutableArray new];
    self.addMoreArr=[NSMutableArray new];
    self.type=@"0";
    self.name=@"";
    self.pageSize=10;
    self.currentPage=1;
    //GPOS移动商家
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];
    __weak typeof(self) weakSelf = self;
    [SVProgressHUD showWithStatus:@"加载中"];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
    [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD dismiss];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            [self initUI:self.isNum];
            [mainCollectionView.mj_header endRefreshing];
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                [SVProgressHUD dismiss];
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.status=[[data objectForKey:@"status"] integerValue];
                    group.address=[data objectForKey:@"address"];
                    group.phone=[data objectForKey:@"phone"];
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"name"];
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.picture=[data objectForKey:@"picture"];
                    group.descript=[data objectForKey:@"description"];

                    [weakSelf.AllArr addObject:group];
                }
                [weakSelf initUI:weakSelf.isNum];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                [SVProgressHUD dismiss];
                
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            else{
                
                [SVProgressHUD dismiss];
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                [weakSelf initUI:weakSelf.isNum];
                [mainCollectionView.mj_header endRefreshing];
            }
        }
        
    }];
    //查看店铺分类
    NSDictionary *dics=@{@"":@""};
    [GPosAPI requestverifyMerchantTypeWithParams:dics andCallback:^(id obj) {
        
        weakSelf.typeArr=[obj objectForKey:@"data"];
        NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
        for (data in weakSelf.typeArr)
        {
            
            MerChantModel *group=[[MerChantModel alloc] init];
            
            group.type=[data objectForKey:@"key"];
            group.name=[data objectForKey:@"value"];
            
            [weakSelf.typeArr1 addObject:group];
        }
        MerChantModel *group1=[[MerChantModel alloc] init];
        group1.type=@"0";
        group1.name=@"所有";
        [weakSelf.typeArr1 addObject:group1];
        
    }];
    
    
    //GPOS智能商家数据请求
    self.GPOSArray=[NSMutableArray new];
    self.pages=1;
    self.AllArrRight=[NSMutableArray new];
    NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:@(self.pages),@"page", nil];
    [GPosAPI requestGposZNMerchantWithParams:dict andCallback:^(id obj) {
        NSLog(@"%@",obj);
        if (obj==nil)
        {
            [weakSelf.rightCollectView.mj_header endRefreshing];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
        if ([[obj objectForKey:@"code"] integerValue]==1)//请求成功
        {
            NSDictionary *GposDic=[NSDictionary new];
            GposDic=[obj objectForKey:@"data"];
            self.GPOSArray=[GposDic objectForKey:@"datas"];
            NSString *imageStr=@"http://wzapi.chuxiaocheng.com";
            for (NSDictionary *dic in self.GPOSArray)
            {
                MerChantModel *group=[[MerChantModel alloc] init];
                group.address=[dic objectForKey:@"shop_address"];
                group.phone=[dic objectForKey:@"mer_phone"];
                group.type=[dic objectForKey:@"shop_type"];
                group.name=[dic objectForKey:@"shop_name"];
                group.ids=[[dic objectForKey:@"id"] integerValue];
                group.shop_headImage=[NSString stringWithFormat:@"%@%@",imageStr,[dic objectForKey:@"shop_head_img"]];
                group.shop_faceImage=[NSString stringWithFormat:@"%@%@",imageStr,[dic objectForKey:@"shop_face_img"]];
                [weakSelf.AllArrRight addObject:group];
                NSLog(@"%@",weakSelf.AllArrRight);
                
            }
            [self.rightCollectView reloadData];
            
        }else{//失败
            
            [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"msg"]];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
      
            [self.rightCollectView.mj_header endRefreshing];
        }
            
        }
    }];
    
    //判断网络状态
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(doWork:) name:@"netStatus" object:nil];
   
}
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
    [self.searchBar resignFirstResponder];
}
-(void)loadMoreShops{
    
     __weak typeof(self) weakSelf = self;
        weakSelf.currentPage++;
    
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];

   
    [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                
                weakSelf.newsAddArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.newsAddArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.status=[[data objectForKey:@"status"] integerValue];
                    group.address=[data objectForKey:@"address"];
                    group.phone=[data objectForKey:@"phone"];
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"name"];
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.picture=[data objectForKey:@"picture"];
                     group.descript=[data objectForKey:@"description"];
                    [weakSelf.AllArr addObject:group];
                }
                [weakSelf.dataArr addObjectsFromArray:weakSelf.newsAddArr];

                
                [mainCollectionView reloadData];
                [mainCollectionView.mj_footer endRefreshing];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                [SVProgressHUD dismiss];
                
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            
            else{
                
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
        }
        
    }];
    
}
-(void)loadNewShops{
    
    self.isNum=0;
    self.dataArr=[NSMutableArray new];
    self.AllArr=[NSMutableArray new];
    self.pageSize=10;
    self.currentPage=1;
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];
    __weak typeof(self) weakSelf = self;
    
    [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [mainCollectionView.mj_header endRefreshing];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
       
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
              
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.status=[[data objectForKey:@"status"] integerValue];
                    group.address=[data objectForKey:@"address"];
                    group.phone=[data objectForKey:@"phone"];
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"name"];
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.picture=[data objectForKey:@"picture"];
                     group.descript=[data objectForKey:@"description"];
                    [weakSelf.AllArr addObject:group];
                }
                [mainCollectionView.mj_header endRefreshing];
                [mainCollectionView reloadData];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                [SVProgressHUD dismiss];
                
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            
            else{
                
                [mainCollectionView.mj_header endRefreshing];

                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
               
            }
        }
        
    }];
    
}
-(void)doWork:(NSNotification*)text
{
    NSString * netVal= text.userInfo[@"netType"];
    
    if ([netVal isEqualToString:@"notReachable"]) {
       
        NSLog(@"网络已断开");
        [SVProgressHUD dismiss];
        [mainCollectionView.mj_header endRefreshing];
    }else{
    
        self.isNum=0;
        self.dataArr=[NSMutableArray new];
        self.addArr=[NSMutableArray new];
        self.newsAddArr=[NSMutableArray new];
        self.AllArr=[NSMutableArray new];
        self.typeArr=[NSMutableArray new];
        self.typeArr1=[NSMutableArray new];
        self.type=@"0";
        self.name=@"";
        self.pageSize=10;
        self.currentPage=1;
        self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];
        __weak typeof(self) weakSelf = self;
        
        [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
            if (obj==nil)
            {
               
                [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }else{
                
                if ([[obj objectForKey:@"code"] integerValue] ==200)
                {
                    
                    weakSelf.dataArr=[obj objectForKey:@"data"];
                    NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                    for (data in weakSelf.dataArr)
                    {
                        
                        MerChantModel *group=[[MerChantModel alloc] init];
                        group.status=[[data objectForKey:@"status"] integerValue];
                        group.address=[data objectForKey:@"address"];
                        group.phone=[data objectForKey:@"phone"];
                        group.type=[data objectForKey:@"type"];
                        group.name=[data objectForKey:@"name"];
                        group.ids=[[data objectForKey:@"id"] integerValue];
                        group.picture=[data objectForKey:@"picture"];
                        [weakSelf.AllArr addObject:group];
                    }
                   
                }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                    
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                    
                    
                    UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                    XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                    VC.hidesBottomBarWhenPushed=YES;
                    //设置当前窗口的根控制器
                    [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                    [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                    
                }
                else{
                    
                    [SVProgressHUD dismiss];
                    [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                    [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                   
                }
            }
            
        }];
        [mainCollectionView reloadData];
        //查看店铺分类
        NSDictionary *dics=@{@"":@""};
        [GPosAPI requestverifyMerchantTypeWithParams:dics andCallback:^(id obj) {
            
            weakSelf.typeArr=[obj objectForKey:@"data"];
            NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
            for (data in weakSelf.typeArr)
            {
                
                MerChantModel *group=[[MerChantModel alloc] init];
                
                group.type=[data objectForKey:@"key"];
                group.name=[data objectForKey:@"value"];
                
                [weakSelf.typeArr1 addObject:group];
            }
            MerChantModel *group1=[[MerChantModel alloc] init];
            group1.type=@"0";
            group1.name=@"所有";
            [weakSelf.typeArr1 addObject:group1];
            
        }];
    }
    
}
-(void)initUI:(NSInteger)num{
    
    
    self.searchView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width, 44)];
    self.searchView.backgroundColor=[UIColor whiteColor];
    NSArray *segmentedArray = [NSArray arrayWithObjects:@"GPOS移动商家",@"GPOS智能商家",nil];
    _segmentedControl = [[UISegmentedControl alloc]initWithItems:segmentedArray];
    _segmentedControl.frame = CGRectMake(35, 5, self.view.frame.size.width-105, 37);
    self.segmentedControl.segmentedControlStyle= UISegmentedControlStyleBar;//设置
    
    self.segmentedControl.tintColor = [UIColor colorWithRed:88/255 green:113/255 blue:255/255 alpha:1];
    _segmentedControl.selectedSegmentIndex = 0;
    [_segmentedControl addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
    [self.searchView addSubview:self.segmentedControl];
   
//    UIView*titleView = [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width-100,30)];
    _titleView = [[UIView alloc]initWithFrame:CGRectMake(0,kNavbarHeight,self.view.frame.size.width,40)];
    _titleView.backgroundColor=[UIColor whiteColor];
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(40, 5, self.view.frame.size.width-100, 30)];
    
    self.searchBar.placeholder = @"请输入商户名";
    self.searchBar.layer.cornerRadius = 15;
    self.searchBar.layer.masksToBounds = YES;
    //设置背景图是为了去掉上下黑线
    self.searchBar.backgroundImage = [[UIImage alloc] init];
    //设置背景色
    self.searchBar.backgroundColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.1];
    // 修改cancel
    self.searchBar.showsCancelButton=NO;
    self.searchBar.barStyle=UIBarStyleDefault;
    self.searchBar.delegate=self;
    self.searchBar.keyboardType=UIKeyboardTypeDefault;
    // 修改cancel
    self.searchBar.showsSearchResultsButton=NO;
    //5. 设置搜索Icon
    [self.searchBar setImage:[UIImage imageNamed:@"icon_sousuo"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    //一下代码为修改placeholder字体的颜色和大小
    UITextField*searchField = [_searchBar valueForKey:@"_searchField"];
    //2. 设置圆角和边框颜色
    if(searchField) {
        [searchField setBackgroundColor:[UIColor clearColor]];
        
        [searchField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    }
    // 输入文本颜色
    searchField.textColor= [UIColor blackColor];
    searchField.font= [UIFont systemFontOfSize:15];
    // 默认文本大小
    [searchField setValue:[UIFont boldSystemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
    //只有编辑时出现出现那个叉叉
    searchField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_titleView addSubview:self.searchBar];
    //Set to titleView
    self.navigationItem.titleView = self.searchView;
    [self.view addSubview:_titleView];
    //右边创建2个按钮(使最后一个靠右侧)
    UIButton *btn1 = [[UIButton alloc] initWithFrame:CGRectMake(_titleView.frame.size.width-37,9, 22, 22)];
//    UIButton *btn2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
    [btn1 setImage:[UIImage imageNamed:@"icon_fenlei_sc"] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(popView)forControlEvents:UIControlEventTouchUpInside];
    
//    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithCustomView:btn1];
//    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithCustomView:btn2];
//
    //设置2个按钮之间的间距
    UIBarButtonItem *itemSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
     itemSpace.width = 20;
    
//    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: item1,itemSpace,item2,nil]];
    [_titleView addSubview:btn1];
    self.topSmallView=[[UIView alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_titleView.frame)+5 , self.view.frame.size.width-20, 60)];
    self.topSmallView.backgroundColor=[UIColor whiteColor];
    self.topSmallView.userInteractionEnabled=YES;
    self.topSmallView.layer.cornerRadius=4;
    UITapGestureRecognizer *tapTop=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popViewLeft:)];
    tapTop.delegate=self;
    [self.topSmallView addGestureRecognizer:tapTop];
    UIImageView *jaho=[[UIImageView alloc] initWithFrame:CGRectMake(self.topSmallView.frame.size.width/2-8, 5, 16, 16)];
    jaho.image=[UIImage imageNamed:@"icon_jiahao1"];
    UILabel *topLab=[[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(jaho.frame)+3, self.topSmallView.frame.size.width, 30)];
    topLab.text=@"预约成为GPOS合作商家";
    topLab.textColor=[UIColor grayColor];
    topLab.textAlignment=NSTextAlignmentCenter;
    [self.topSmallView addSubview:topLab];
    [self.topSmallView addSubview:jaho];
    [self.view addSubview:self.topSmallView];
   
    
//    self.rightCollectView.hidden = NO;
//    mainCollectionView.hidden = YES;
////    sender.selectedSegmentIndex = 1;
//    self.topSmallView.hidden=YES;
////    _tag=1;
//    self.searchBar.hidden=YES;
//    self.titleView.hidden=YES;

    [self creatCollectionView];

}

//点击键盘上搜索时的相应事件
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    [self.searchBar resignFirstResponder];
    self.isNum=0;
    self.dataArr=[NSMutableArray new];
    self.AllArr=[NSMutableArray new];
    self.pageSize=10;
    self.currentPage=1;
    self.name=self.searchBar.text;
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];
    __weak typeof(self) weakSelf = self;
    
    [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.status=[[data objectForKey:@"status"] integerValue];
                    group.address=[data objectForKey:@"address"];
                    group.phone=[data objectForKey:@"phone"];
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"name"];
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.picture=[data objectForKey:@"picture"];
                    [weakSelf.AllArr addObject:group];
                }
                
                [mainCollectionView reloadData];
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                [SVProgressHUD dismiss];
                
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            else{
                
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
            }
        }
        
    }];
    
}
//跳转商家入驻
-(void)popViewLeft:(UIGestureRecognizer *)tp{
    
    MerchentEntryViewController *vc=[[MerchentEntryViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    vc.hidesBottomBarWhenPushed = NO;
    
}
-(void)creatCollectionView{
   
    //1.初始化layout
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
   
    //该方法也可以设置itemSize
    layout.itemSize =CGSizeMake(self.view.frame.size.width/2-14, 230);
    
    //2.初始化collectionView
    mainCollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.topSmallView.frame), self.view.frame.size.width, KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight-49-60) collectionViewLayout:layout];
    [self.view addSubview:mainCollectionView];
    mainCollectionView.backgroundColor = [UIColor clearColor];
    
    //3.注册collectionViewCell
   
    [mainCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([MerChentCollectionViewCell class]) bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"collectionCell"];
    mainCollectionView.alwaysBounceVertical = YES;
    //4.设置代理
    mainCollectionView.delegate = self;
    mainCollectionView.dataSource = self;
    mainCollectionView.mj_header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewShops)];
    [mainCollectionView.mj_header beginRefreshing];
    mainCollectionView.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreShops)];
    
    
    //GPOS智能商家
    
    //1.初始化layout
    UICollectionViewFlowLayout *layout2 = [[UICollectionViewFlowLayout alloc] init];
    
    //该方法也可以设置itemSize
    layout2.itemSize =CGSizeMake(self.view.frame.size.width/2-14, 200);
    
    //2.初始化collectionView
    self.rightCollectView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, kNavbarHeight, self.view.frame.size.width, KmainScreenHeiht - kNavbarHeight) collectionViewLayout:layout2];
//    [self.view addSubview:self.rightCollectView];
    self.rightCollectView.backgroundColor = [UIColor clearColor];
    
    //3.注册collectionViewCell
    
    [self.rightCollectView registerNib:[UINib nibWithNibName:NSStringFromClass([MerchsCollectionViewCell class]) bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"collect"];
    self.rightCollectView.alwaysBounceVertical = YES;
    //4.设置代理
    self.rightCollectView.delegate = self;
    self.rightCollectView.dataSource = self;
  
    self.rightCollectView.mj_header=[MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewShopsRight)];
    [self.rightCollectView.mj_header beginRefreshing];
    self.rightCollectView.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreShopsRight)];
}
-(void)loadMoreShopsRight{
    
    __weak typeof(self) weakSelf = self;
    weakSelf.pages++;
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@(weakSelf.pages),@"page", nil];
    [GPosAPI requestGposZNMerchantWithParams:dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [weakSelf.rightCollectView.mj_header endRefreshing];
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue]==1)//请求成功
            {
                NSDictionary *GposDic=[NSDictionary new];
                GposDic=[obj objectForKey:@"data"];
                NSMutableArray *arr1=[NSMutableArray new];
                arr1=[GposDic objectForKey:@"datas"];
                
                for (NSDictionary *dic in arr1)
                {
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.address=[dic objectForKey:@"shop_address"];
                    group.phone=[dic objectForKey:@"mer_phone"];
                    group.type=[dic objectForKey:@"shop_type"];
                    group.name=[dic objectForKey:@"shop_name"];
                    group.ids=[[dic objectForKey:@"id"] integerValue];
                    group.shop_headImage=[dic objectForKey:@"shop_head_img"];
                    group.shop_faceImage=[dic objectForKey:@"shop_face_img"];
                    [weakSelf.addMoreArr addObject:group];
               
                }
                
                 [weakSelf.AllArrRight addObjectsFromArray:weakSelf.addMoreArr];
                [weakSelf.rightCollectView reloadData];
                [weakSelf.rightCollectView.mj_footer endRefreshing];
            }else{//失败
                [weakSelf.rightCollectView.mj_footer endRefreshing];
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"msg"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                [self.rightCollectView.mj_header endRefreshing];
            }
            
        }
    }];
    
}
//gpos智能商家
-(void)loadNewShopsRight{
    __weak typeof(self) weakSelf = self;

    self.GPOSArray=[NSMutableArray new];
    self.pages=1;
    self.AllArrRight=[NSMutableArray new];
    NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:@(self.pages),@"page", nil];
    [GPosAPI requestGposZNMerchantWithParams:dict andCallback:^(id obj) {
        NSLog(@"%@",obj);
        if ([[obj objectForKey:@"code"] integerValue]==1)//请求成功
        {
            NSDictionary *GposDic=[NSDictionary new];
            GposDic=[obj objectForKey:@"data"];
            self.GPOSArray=[GposDic objectForKey:@"datas"];
            NSString *imageStr=@"http://cxcapi.chuxiaocheng.cn";
            for (NSDictionary *dic in self.GPOSArray)
            {
                MerChantModel *group=[[MerChantModel alloc] init];
                group.address=[dic objectForKey:@"shop_address"];
                group.phone=[dic objectForKey:@"mer_phone"];
                group.type=[dic objectForKey:@"shop_type"];
                group.name=[dic objectForKey:@"shop_name"];
                group.ids=[[dic objectForKey:@"id"] integerValue];
                group.shop_headImage=[NSString stringWithFormat:@"%@%@",imageStr,[dic objectForKey:@"shop_head_img"]];
                group.shop_faceImage=[NSString stringWithFormat:@"%@%@",imageStr,[dic objectForKey:@"shop_face_img"]];
            
                [weakSelf.AllArrRight addObject:group];
                
            }
            [weakSelf.rightCollectView reloadData];
            [weakSelf.rightCollectView.mj_header endRefreshing];
            
        }else{//失败
            
             [weakSelf.rightCollectView.mj_header endRefreshing];
        }
    }];
    
}
-(void)indexDidChangeForSegmentedControl:(UISegmentedControl *)sender
{
    NSInteger selecIndex = sender.selectedSegmentIndex;
    switch(selecIndex){
        case 0:
            mainCollectionView.hidden = NO;
            self.rightCollectView.hidden = YES;
            self.topSmallView.hidden=NO;
            sender.selectedSegmentIndex=0;
            self.searchBar.hidden=NO;
            self.titleView.hidden=NO;
            _tag = 0;
            [mainCollectionView reloadData];
            
            break;
            
        case 1:
           
            self.rightCollectView.hidden = NO;
            mainCollectionView.hidden = YES;
            sender.selectedSegmentIndex = 1;
            self.topSmallView.hidden=YES;
            _tag=1;
            self.searchBar.hidden=YES;
            self.titleView.hidden=YES;

            [self.view addSubview:self.rightCollectView];

            [self.rightCollectView reloadData];
            break;
            
        default:
            break;
    }
    
}
//导航栏弹出小视图的点击方法
-(void)popView{
    
    self.bigView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    self.bigView.backgroundColor=[[UIColor blackColor]colorWithAlphaComponent:0.01];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismisView:)];
    tap.delegate=self;
    [self.bigView addGestureRecognizer:tap];
    self.smallView=[[UIView alloc] init];
    self.smallView.backgroundColor=[UIColor clearColor];
 self.smallView.frame=CGRectMake(self.view.frame.size.width-85,kNavbarHeight+27, 80, 150);
    
    self.imageV=[[UIImageView alloc] init];
    self.imageV.frame=CGRectMake(0, 0, self.smallView.frame.size.width, self.smallView.frame.size.height);
    self.imageV.userInteractionEnabled=YES;
    self.imageV.image=[UIImage imageNamed:@"icon_feileik"];
    [self.smallView addSubview:self.imageV];
    
    self.tables=[[UITableView alloc] init];
    self.tables.delegate=self;
    self.tables.dataSource=self;
    self.tables.tableFooterView=[[UIView alloc] init];
    self.tables.backgroundColor=[UIColor clearColor];
    self.tables.frame=CGRectMake(2, 8, self.imageV.frame.size.width-4, self.imageV.frame.size.height-8);
    self.tables.showsHorizontalScrollIndicator=NO;
    self.tables.showsVerticalScrollIndicator=NO;
    self.tables.separatorInset = UIEdgeInsetsZero;
    self.tables.layoutMargins=UIEdgeInsetsZero;
    [self.imageV addSubview:self.tables];
    [self.bigView addSubview:self.smallView];
    //加到全屏
    [[UIApplication sharedApplication].keyWindow addSubview:self.bigView];
  
}
-(void)dismisView:(UITapGestureRecognizer *)tp{
    
    [UIView animateWithDuration:0.6 animations:^{
        
    } completion:^(BOOL finished) {
        
        self.bigView.hidden=YES;
        
    }];
    
}
//手势的代理(点击大的视图，防止触发小的视图)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
    if ([touch.view isDescendantOfView:self.smallView]) {
        return NO;
    }
    return YES;
}
#pragma mark collectionView代理方法

//每个section的item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.tag==0)
    {
        return self.dataArr.count;
    }else if (self.tag==1){
        
        return self.GPOSArray.count;
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.tag==0) {
        
     MerChentCollectionViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
   
    cell.backgroundColor=[UIColor whiteColor];
    cell.layer.cornerRadius=8;
    cell.models=self.AllArr[indexPath.row];
    return cell;
    }else
    {
        
        MerchsCollectionViewCell* cells = [collectionView dequeueReusableCellWithReuseIdentifier:@"collect" forIndexPath:indexPath];
        
        cells.backgroundColor=[UIColor whiteColor];
        cells.layer.cornerRadius=8;
        cells.models=self.AllArrRight[indexPath.row];
        return cells;
        
    }
   
}

//设置每个item的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.tag==0) {
        
    
    return CGSizeMake(self.view.frame.size.width/2-18, 230);
    }else{
        
    return CGSizeMake(self.view.frame.size.width/2-18, 200);
        
    }
}


//设置每个item的UIEdgeInsets
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

//设置每个item水平间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}


//设置每个item垂直间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}

//点击item方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
   
   [_searchBar resignFirstResponder];
    if (self.tag==0) {
        
    
    MerChantInfoViewController *vc=[[MerChantInfoViewController alloc] init];
    MerChantModel *model=[[MerChantModel alloc] init];
    model=self.AllArr[indexPath.row];
//    vc.topImages=model.pictuers;
    vc.pictArr=model.picture;
    vc.nameStr=model.name;
    vc.typeStr=model.type;
    vc.addStr=model.address;
    vc.phoneStr=model.phone;
    vc.descriptios=model.descript;
    vc.numm=self.tag;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    vc.hidesBottomBarWhenPushed = NO;
    }else{
        NSMutableArray *arr=[NSMutableArray new];
        MerChantInfoViewController *vc=[[MerChantInfoViewController alloc] init];
        MerChantModel *model=[[MerChantModel alloc] init];
        model=self.AllArrRight[indexPath.row];
     
        [arr addObject:model.shop_headImage];
        [arr addObject:model.shop_faceImage];
        vc.pictArr=arr;
        vc.nameStr=model.name;
        vc.typeStr=model.type;
        vc.addStr=model.address;
        vc.phoneStr=model.phone;
        vc.numm=self.tag;
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        vc.hidesBottomBarWhenPushed = NO;
        
    }
}

#pragma table的代理
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.typeArr.count+1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 40;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SmallTableViewCell *cell=[[[NSBundle mainBundle] loadNibNamed:@"SmallTableViewCell" owner:self options:nil] firstObject];
    
    MerChantModel *model=self.typeArr1[indexPath.row];
    cell.nameLab.text=[NSString stringWithFormat:@"%@",model.name];
    cell.backgroundColor=[UIColor clearColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MerChantModel *model=self.typeArr1[indexPath.row];
    
    [self reloadCollect:model];
    
}
-(void)reloadCollect:(MerChantModel *)model{
    __weak typeof(self) weakSelf = self;
    self.isNum=1;
    self.dataArr=[NSMutableArray new];
    self.AllArr=[NSMutableArray new];
    self.type=model.type;
    self.name=@"";
    self.pageSize=10;
    self.currentPage=1;
    self.dic=[NSDictionary dictionaryWithObjectsAndKeys:self.type,@"type",self.name,@"name",@(self.pageSize),@"pageSize",@(self.currentPage),@"currentPage", nil];
    [GPosAPI requestverifyAllMerchantWithParams:self.dic andCallback:^(id obj) {
        if (obj==nil)
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败,请检查您的网络状态"];
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
            weakSelf.bigView.hidden=YES;
//            weakSelf.im.hidden=NO;
//            self->mainCollectionView.hidden=YES;
            
        }else{
            
            if ([[obj objectForKey:@"code"] integerValue] ==200)
            {
                
                weakSelf.dataArr=[obj objectForKey:@"data"];
                NSMutableDictionary *data=[[NSMutableDictionary alloc]init];
                for (data in weakSelf.dataArr)
                {
                    
                    MerChantModel *group=[[MerChantModel alloc] init];
                    group.status=[[data objectForKey:@"status"] integerValue];
                    group.address=[data objectForKey:@"address"];
                    group.phone=[data objectForKey:@"phone"];
                    group.type=[data objectForKey:@"type"];
                    group.name=[data objectForKey:@"name"];
                    group.ids=[[data objectForKey:@"id"] integerValue];
                    group.picture=[data objectForKey:@"picture"];
                    group.descript=[data objectForKey:@"description"];
                    for (NSDictionary *dic in group.picture)
                    {
                        group.pictuers=[dic objectForKey:@"uri"];
                    }
                    [weakSelf.AllArr addObject:group];
                    
                }
                
//                if (weakSelf.AllArr.count==0)
//                {
//                    weakSelf.im.hidden=NO;
//                    self->mainCollectionView.hidden=YES;
//                }else{
//
//                    weakSelf.im.hidden=YES;
//                    self->mainCollectionView.hidden=NO;
//                }
                weakSelf.bigView.hidden=YES;
                
            }else if ([[obj objectForKey:@"code"] integerValue]==401 || [[obj objectForKey:@"code"] intValue] == 402){
                
                 [[NSNotificationCenter defaultCenter] postNotificationName:@"NewLoginInView" object:nil];
                UIStoryboard * mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                XMRegisterViewController *VC = [mainStory instantiateInitialViewController];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"passWord"];
                VC.hidesBottomBarWhenPushed=YES;
                //设置当前窗口的根控制器
                [UIApplication sharedApplication].keyWindow.rootViewController=VC;
                [SVProgressHUD showInfoWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                
                
            }
            else{
                
                [SVProgressHUD showErrorWithStatus:[obj objectForKey:@"message"]];
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
                weakSelf.bigView.hidden=YES;
//                weakSelf.im.hidden=NO;
//                self->mainCollectionView.hidden=YES;

               
            }
        }
        [self->mainCollectionView reloadData];
    }];
    
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [_searchBar resignFirstResponder];
    return indexPath;
}
// 滑动的时候 searchBar 回收键盘
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [_searchBar resignFirstResponder];
}
-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"netStatus" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"uploadCurrentView" object:nil];
    
}
-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [SVProgressHUD dismiss];
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
}
#pragma mark - TableView 占位图

- (UIImage *)xy_noDataViewImage {
    return [UIImage imageNamed:@"icon_wshuju"];
}

- (NSString *)xy_noDataViewMessage {
    return @"暂时没有相关数据哦";
}

- (UIColor *)xy_noDataViewMessageColor {
    return [UIColor blackColor];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
